package mo.daliy;

import java.util.*;

public class L3112 {

    public int[] minimumTime(int n, int[][] edges, int[] disappear) {
        List<int[]>[] graph = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            graph[i] = new ArrayList<>();
        }
        for (int i = 0; i < edges.length; i++) {
            graph[edges[i][0]].add(new int[]{edges[i][1], edges[i][2]});
            graph[edges[i][1]].add(new int[]{edges[i][0], edges[i][2]});
        }

        PriorityQueue<int[]> priorityQueue = new PriorityQueue<>(Comparator.comparingInt(p -> p[1]));
        priorityQueue.add(new int[]{0, 0});
        int[] res = new int[n];
        Arrays.fill(res, -1);
        while (!priorityQueue.isEmpty()) {
            int[] cur = priorityQueue.poll();
            if (res[cur[0]] != -1) {
                continue;
            }
            int distance = cur[1];
            res[cur[0]] = distance;

            List<int[]> endNodes = graph[cur[0]];
            for (int[] end : endNodes) {
                if (res[end[0]] != -1) {
                    continue;
                }
                if (distance + end[1] >= disappear[end[0]]) {
                    continue;
                }
                priorityQueue.add(new int[]{end[0], distance+end[1]});
            }
        }
        return res;
    }


    public static void main(String[] args) {
        L3112 test = new L3112();
        System.out.println(Arrays.toString(test.minimumTime(2, new int[][]{{0, 1, 1}}, new int[]{1, 1})));

    }
}
